package com.neu.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.neu.po.User;
import com.neu.util.DBUtil;

public class Userlmpl implements UserDao{

	@Override
	public User login(String username, String password) throws ClassNotFoundException, SQLException {
		String sql = "select * from admin where username = ? and password =?";
		Connection connection = DBUtil.getConnection();
		ResultSet rs = DBUtil.executeQuery(connection, sql, username,password);
		
		User user = null;
		int id;
		if(rs.next()) {
			id = rs.getInt("id");
			username = rs.getString("username");
			password = rs.getString("password");
			
			user = new User(id, username, password);
		}
		
		DBUtil.closeConnection(connection);
		return user;
	}

}
